< previous page page_106 next page >

Page 106
e10a6a0a59f035e870d90cca05b85fce.gif
    LogicalPalette = picCanvas.Picture.hPal
    If ResizePalette(LogicalPalette, SysPalSize) = 0 Then
        MsgBox "Error resizing the palette."
        End
    End If

    ' Flag all palette entries as PC_EXPLICIT.
    ' Set peRed to the system palette indexes.
    For i = 0 To SysPalSize - 1
        palentry(i).peRed = i
        palentry(i).peFlags = PC_EXPLICIT
    Next i

    ' Update the palette (ignore return value).
    i = SetPaletteEntries(LogicalPalette, 0, _
        SysPalSize, palentry(0))
End Sub
Example program PalWatch, shown in Figure 3.10 together with the Viewer program, uses this subroutine to display the values in the system color palette. It uses the LoadSystemPalette subroutine to copy the system palette colors into the picCanvas control's logical palette.
PalWatch then uses palette-indexed colors to draw boxes using each of the colors in the logical palette. Because these colors match those in the system palette, the picture box shows the colors in the system palette. The program covers the static colors with a diagonal hatch pattern. If you click on one of the colors, the program displays the color's red, green, and blue components in its menu bar.
When you run other programs, their logical color palettes may require changes to the system color palette. If you leave PalWatch running, it automatically updates to display the new system palette colors.
PalWatch can be particularly useful when you are writing programs that manipulate palettes. Unless a program draws with all the colors in its logical palette, you will not be
0106-01.jpg
Figure 3.10
Example program PalWatch displays the current system palette colors.

 
< previous page page_106 next page >